//
// Created by yewei on 2021/9/19.
//

#include <bits/stdc++.h>

using namespace std;

const int MAXV=100;
struct node{
    int weight;
    vector<int> child;
}Node[MAXV];
int P[MAXV]; //输出结点路径时用到该数组
int S; //需要的总和

void DFS(int start,int sum,int numNode);
bool cmp(int a,int b);

int main(){
    freopen("../A1053.txt","r",stdin);
    int N,M;
    cin>>N>>M>>S;
    for(int i=0;i<N;i++)
        cin>>Node[i].weight;
    for(int i=0;i<M;i++){
        int id,k,id1;
        cin>>id>>k;
        for(int j=0;j<k;j++){
            cin>>id1;
            Node[id].child.push_back(id1);
        }
        sort(Node[id].child.begin(),Node[id].child.end(),cmp);
    }

    P[0] = Node[0].weight;
    DFS(0,Node[0].weight,1);

    return 0;
}

void DFS(int start,int sum,int numNode){
    if(sum>S) return;
    if(sum==S){
        if(!Node[start].child.empty()) return;
        for(int i=0;i<numNode;i++){
            if(i!=0) cout<<" ";
            cout<<P[i];
        }
        cout<<endl;
        return;
    }
    for(int i=0;i<Node[start].child.size();i++){
//        sum += Node[Node[start].child[i]].weight;  //sum不能写在这里，因为选择不同子结点时，sum不会累加
        P[numNode] = Node[Node[start].child[i]].weight; //同样道理，numNode也得在下一行传参时才能累加
        DFS(Node[start].child[i],sum+Node[Node[start].child[i]].weight,numNode+1); //sum应该写在这里，这样兄弟结点就不会累加了
    }
}
bool cmp(int a,int b){
    return Node[a].weight>Node[b].weight;
}
